<template>
<div class="app-container">
  <div style="margin:0 0 10px 0;">
    <el-button @click="add" type="primary" size="small">添加管理员</el-button>
  </div>
  <el-table ref="multipleTable" v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row @selection-change="handleSelectionChange" empty-text="暂无数据">
    <el-table-column type="selection" width="60">
    </el-table-column>
    <el-table-column label="编号" width="150">
      <template slot-scope="scope">
        {{ scope.$index }}
      </template>
    </el-table-column>
    <el-table-column label="管理员名称">
      <template slot-scope="scope">
        {{ scope.row.name }}
      </template>
    </el-table-column>
    <el-table-column label="联系电话" width="110">
      <template slot-scope="scope">
        <span>{{ scope.row.phone }}</span>
      </template>
    </el-table-column>
    <el-table-column label="添加日期" width="110">
      <template slot-scope="scope">
        {{ scope.row.date }}
      </template>
    </el-table-column>
    <el-table-column class-name="status-col" label="最后登录时间" width="180">
      <template slot-scope="scope">
        <!-- <el-tag :type="scope.row.dataLogin | statusFilter">{{ scope.row.status }}</el-tag> -->
        {{scope.row.dataLogin}}
      </template>
    </el-table-column>
    <el-table-column label="操作" width="100">
      <template slot-scope="scope">
        <el-button @click="edit(scope.row)" type="text">编辑</el-button>
        <el-button type="text" style="color:#ff0000;">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div style="margin:10px 0 0 0;text-align:right;">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 30, 50, 100]"
      :page-size="1"
      layout="total, sizes, prev, pager, next, jumper"
      :total="10">
    </el-pagination>
  </div>
</div>
</template>

<script>
import {
  getList
} from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [{
          name: 'test',
          phone: '13322221111',
          date: '2021-02-03',
          dataLogin: '2021-02-03 22:22:22',
        },
        {
          name: 'test1',
          phone: '13322221111',
          date: '2021-02-03',
          dataLogin: '2021-02-03 22:22:22',
        }
      ],
      multipleSelection: [],
      listLoading: true,
      currentPage: 1,
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    add() {
      this.$router.push({
        path: '/administrators/add'
      })
    },
    edit(row) {
      console.log(row)
      this.$router.push({
        path: '/administrators/edit'
      })
    },
    fetchData() {
      this.listLoading = true
      getList().then(response => {
        // this.list = response.data.items
        this.listLoading = false
      })
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
}
</script>
